<?php
//vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldcolumn=1 foldmethod=marker:
/**
 * 项目：   LTEBBS
 * 文件：   class/message/ShowSendMsg.class.php
 *
 * 显示用户发件箱的短消息
 *
 * PHP Version 5
 *
 * @package:   class.message
 * @author:    Mike.G   Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: http://www.5anet.com
 * @version:   $Id: ShowSendMsg.class.php,v 1.1.1.1 2006-08-28 13:09:20 ghw Exp $
 * @date:      $Date: 2006-08-28 13:09:20 $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';
include_once CLASS_PATH.'user/UserUtil.class.php';

include_once FUNCTION_PATH.'ConvertString.fun.php';


//include the language file
if ( file_exists(LANG_PATH.SYSTEM_LANG.'/ShowSendMsg.lang.php') ) {
   include_once LANG_PATH.SYSTEM_LANG.'/ShowSendMsg.lang.php';
}


class ShowSendMsg extends BaseAction {
   /**
    * 数据库的连接
    */
   public $db;

   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }

   /**
    * 显示短消息的内容
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function run() {
      //读取用户传入的id
      $id = $this->getParameterFromGET('id');

      if ( !$id ) {
         $this->AlertAndBack(SR_ID_IS_EMPTY);
         return;
      }

      //求得用户的id
      $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']);

      //验证id是否存在
      $sql = 'select count(*) as num from message_outbox where id=? and user_id=?';
      $sth = $this->db->Prepare($sql);
      $res = $this->db->Execute($sth, array($id, $user_id));
      $rows = $res->FetchRow();

      if ( !$rows['num'] ) {
         $this->AlertAndBack(SR_ID_IS_NOT_EXISTS_OR_NOT_BELONE_USER);
         return;
      }


      $smarty = $this->getSmarty();


      $smarty = $this->getSmarty();
      $user_name = $_SESSION['user']['name'];
      $smarty->assign('view_user_name', $user_name);

      //用户的所在组
      $sql = 'select b.group_name from base_user_info as a join sys_group as b on '.
         ' a.group_dep = b.id where a.id=?';
      $sth = $this->db->Prepare($sql);
      $res = $this->db->Execute($sth, array($user_id));
      $rows = $res->FetchRow();

      $smarty->assign('user_roles', $rows['group_name']);

      //查询短消息的内容
      $sql = 'select a.title, a.send_time, a.content, b.user_name from message_outbox a '.
         ' join base_user_info b on a.receive_user_id = b.id where a.id=?';

      $sth = $this->db->Prepare($sql);
      $res = $this->db->Execute($sth, array($id));
      $rows = $res->FetchRow();

      $smarty->assign('title', $rows['title']);
      $smarty->assign('sender', $rows['user_name']);
      $smarty->assign('send_time', $rows['send_time']);
      $smarty->assign('content', ConvertString($rows['content'], ROOT_URL, IMAGE_URL.'express/'));


      $smarty->display('showsendmsg.tmpl');

   }

}


?>
